/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package quanlysieuthi;

import DTO.CChiTietHoaDon;
import DTO.CHoaDon;
import DTO.CTon_Kho;
import java.sql.Timestamp;
import java.util.List;


public class CKiemTra {
    public static String user_name  = "admin";
    public static long user_id  = 1;
    
    public static void addChiTietHoaDon(CChiTietHoaDon chitiet,List<CChiTietHoaDon> list){
        list.add(chitiet);
    }
    
    public static CHoaDon addHoaDon(String loaiPhieu,long nguoilapId,long nguoiGiaoId,
            long khachHang_Id,String ten,String diaChi,long kho_id,Timestamp ngaynhap){
        CHoaDon hoadon = new CHoaDon();
        hoadon.setKhachHangId(khachHang_Id);
        hoadon.setKhoId(kho_id);
        hoadon.setLoaiPhieu(loaiPhieu);
        hoadon.setNgayNhap(ngaynhap);
        hoadon.setNguoiGiaoId(nguoiGiaoId);
        hoadon.setNguoiLapId(nguoilapId);
        hoadon.setNguoiSua(CKiemTra.user_name);
        hoadon.setNguoiTao(CKiemTra.user_name);        
        return hoadon;
    }
    
    
    public static Boolean isKiemTraSoLuongNhap(CTon_Kho tkho,int Sl){
        if(tkho == null)
            return true;
        int tongSoLuong = Sl + tkho.getSoLuongNhap() - tkho.getSoLuongXuat();
        if(tongSoLuong > tkho.getTonToiDa()){
            return false;
        }
        return true;
    }
    
    public static Boolean isKiemTraSLXuat(CTon_Kho tKho,int Sl){
        if(tKho == null)
            return false;
        int slCon = tKho.getSoLuongNhap() - tKho.getSoLuongXuat() - Sl;
        if(slCon < tKho.getTonToiThieu()){
            return false;
        }
        return true;
    }
    
}
